package com.newcapec.erp.utils;

import com.newcapec.erp.bean.*;
import com.newcapec.erp.main.DataInit;
import com.newcapec.erp.ui.*;

import javax.swing.*;
import java.util.Vector;

public class XMLFUtils {
    public static void updateDataByFirstValue(int type, int index,int currentPage){
        Vector<Vector<String>> data = XMLFReader.getData(type);
        Vector<String> v = data.get(index);
        switch (type){
            case DataInit.TYPE_WAREHOUSE:
                WarehouseEntity warehouseEntity= new WarehouseEntity(v.get(0),v.get(1),v.get(2));
                new UpdateWarehouseUI(warehouseEntity,index,currentPage);
                break;
            case DataInit.TYPE_STORE:
                StoreEntity storeEntity = new StoreEntity(v.get(0),v.get(1),v.get(2),v.get(3),v.get(4),v.get(5));
                new UpdateStoreUI(storeEntity,index,currentPage);
                break;
            case DataInit.TYPE_CLIENT:
                ClientEntity clientEntity= new ClientEntity(v.get(0),v.get(1),v.get(2),v.get(3),v.get(4),v.get(5));
                new UpdateClientUI(clientEntity,index,currentPage);
                break;
            case DataInit.TYPE_SYSTEM:
                UserEntity systemEntity= new UserEntity(v.get(0),v.get(1),v.get(2),v.get(3),v.get(4),v.get(5));
                new UpdateUserUI(systemEntity,index,currentPage);
                break;
            case DataInit.TYPE_INVENTORY:
                InventoryEntity inventoryEntity= new InventoryEntity(v.get(0),v.get(1),v.get(2),v.get(3),v.get(4),v.get(5));
                new UpdateInventoryUI(inventoryEntity,index,currentPage);
                break;
        }
    }

    public static void deleteDataByFirstValue(int type, int index, int currentPage){
        switch (type){
            case DataInit.TYPE_WAREHOUSE:
                XMLFWriter.deleteWarehouse(index);
                JOptionPane.showMessageDialog(null, "恭喜你，删除成功.", "提示",JOptionPane.PLAIN_MESSAGE);
                Vector<Vector<String>> warehouseData = XMLFReader.getData(DataInit.TYPE_WAREHOUSE);
                MainUI.updateMainUI(DataInit.TYPE_WAREHOUSE,warehouseData,currentPage);
                break;
            case DataInit.TYPE_STORE:
                XMLFWriter.deleteStore(index);
                JOptionPane.showMessageDialog(null, "恭喜你，删除成功.", "提示",JOptionPane.PLAIN_MESSAGE);
                Vector<Vector<String>> storeData = XMLFReader.getData(DataInit.TYPE_STORE);
                MainUI.updateMainUI(DataInit.TYPE_STORE,storeData,currentPage);
                break;
            case DataInit.TYPE_CLIENT:
                XMLFWriter.deleteClient(index);
                JOptionPane.showMessageDialog(null, "恭喜你，删除成功.", "提示",JOptionPane.PLAIN_MESSAGE);
                Vector<Vector<String>> clientData = XMLFReader.getData(DataInit.TYPE_CLIENT);
                MainUI.updateMainUI(DataInit.TYPE_CLIENT,clientData,currentPage);
                break;
            case DataInit.TYPE_SYSTEM:
                XMLFWriter.deleteSystem(index);
                JOptionPane.showMessageDialog(null, "恭喜你，删除成功.", "提示",JOptionPane.PLAIN_MESSAGE);
                Vector<Vector<String>> systemData = XMLFReader.getData(DataInit.TYPE_SYSTEM);
                MainUI.updateMainUI(DataInit.TYPE_SYSTEM,systemData,currentPage);
                break;
            case DataInit.TYPE_INVENTORY:
                XMLFWriter.deleteInventory(index);
                JOptionPane.showMessageDialog(null, "恭喜你，删除成功.", "提示",JOptionPane.PLAIN_MESSAGE);
                Vector<Vector<String>> inventoryData = XMLFReader.getData(DataInit.TYPE_INVENTORY);
                MainUI.updateMainUI(DataInit.TYPE_INVENTORY,inventoryData,currentPage);
                break;
            case DataInit.TYPE_USER:
                break;
        }
    }
}
